<?php

class ApiFaceBook extends API {

	function __construct()
	{
		parent::__construct();
		$this->run();
	}

	public function getUserByID($id)
	{
		return $this->formatData($this->wpdb->get_results("SELECT * FROM ".$this->FBLogin." WHERE user_id='".$id."'"),'userProfile');
	}

	public function getUserByEmail($email)
	{
		return $this->formatData($this->wpdb->get_results("SELECT * FROM ".$this->FBLogin." WHERE user_email='".$email."'"),'userProfile');
	}

	public function getUserByUserName($username)
	{
		return $this->formatData($this->wpdb->get_results("SELECT * FROM ".$this->FBLogin." WHERE username='".$username."'"),'userProfile');
	}

	public function getUserLoginInformation($id)
	{
		return $this->formatData($this->wpdb->get_results("SELECT last_login_time,login_count,locale,timezone,location,hometown FROM ".$this->FBLogin." WHERE user_id='".$id."'"),'loginInformation');
	}

	public function getAllUser()
	{
		return $this->formatData($this->wpdb->get_results("SELECT * FROM ".$this->FBLogin),'listUser');
	}

	public function run()
	{
		$data = $this->get();
		if(!empty($data['data'])){
			$this->responseData(200,array_merge(array('error'=>$data['error']),$data['data']));
		}
	}

	public function get()
	{
		$call = $this->getMethod($_GET);
		return $this->validateMethod(array(
			'class'=>$call['class'],
			'currentClass'=>__CLASS__,
			'action'=>$call['action'],
			'data'=>$this->$call['action'](isset($call['id']) ? $call['id'] : null)
		));
	}
}